package com.wlz;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 通过Callable和FutureTask创建线程
 * @author wlz
 *
 */
public class FutureTaskTest implements Callable<String> {
    @Override
    public String call() throws Exception {

        return "return true";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask task = new FutureTask(new FutureTaskTest() {}); // FutureTaskTest 使用FutureTask来包装使用FutureTask来包装MyCallable对象
        Thread thread = new Thread(task);// FutureTask对象作为Thread对象的target创建新的线程
        thread.start();  // 线程进入到就绪状态
        System.out.println(task.get());   // 取得新创建的新线程中的call()方法返回的结果


    }
}
